function ModelObject(){
}

ModelObject.prototype.accel = [0.0,0.0,0.0];
ModelObject.prototype.velocity = [0.0,0.0,0.0];
ModelObject.prototype.pos = [0.0,0.0,0.0];

ModelObject.prototype.vertexData = [];
ModelObject.prototype.normalData = [];
ModelObject.prototype.colorData = [];

ModelObject.prototype.addAccel = function(a){
	accel += a;
}

ModelObject.prototype.move = function(){
	vec3.add(velocity, accel, velocity);
	vec3.add(pos, velocity, pos);
}

	
ModelObject.prototype.getVertexData = function(){
	return ballVertexData;	
}

ModelObject.prototype.getNormalData = function(){
	return ballNormalData;
}

ModelObject.prototype.getColorData = function(){
	return ballColorData;
}



ModelObject.prototype.mvMatrix = mat4.create();
ModelObject.prototype.pMatrix = mat4.create();
ModelObject.prototype.mvMatrixStack = [];


ModelObject.prototype.mvPushMatrix = function() {
	var copy = mat4.create();
	mat4.set(mvMatrix, copy);
	mvMatrixStack.push(copy);
}

ModelObject.prototype.mvPopMatrix = function() {
	if (mvMatrixStack.length == 0) {
		throw "Invalid popMatrix!";
	}
	mvMatrix = mvMatrixStack.pop();
}


ModelObject.prototype.setMatrixUniforms = function(camera, shader) {
	gl.uniformMatrix4fv(shader.pMatrixUniform, false, camera);
	gl.uniformMatrix4fv(shader.mvMatrixUniform, false, mvMatrix);
}

ModelObject.prototype.vertexBuffer;
ModelObject.prototype.colorBuffer;
ModelObject.prototype.normalBuffer;

ModelObject.prototype.initBuffers = function() {
	ballVertexBuffer = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER, ballVertexBuffer);
	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.getVertexData()), gl.STATIC_DRAW);
	ballVertexBuffer.itemSize = 3;
	ballVertexBuffer.numItems = this.getVertexData().length / 3;
		
	ballColorBuffer = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER, ballColorBuffer);
	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.getColorData()), gl.STATIC_DRAW);
	ballColorBuffer.itemSize = 4;
	ballColorBuffer.numItems = this.getVertexData().length / 4;
	
	ballNormalBuffer = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER,  ballNormalBuffer);
	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.getNormalData()), gl.STATIC_DRAW);
	ballNormalBuffer.itemSize = 3;
	ballNormalBuffer.numItems = this.getNormalData() / 3;
}


ModelObject.prototype.draw = function(camera, shader) {
	mvPushMatrix();
	mat4.identity(mvMatrix);
	mat4.translate(mvMatrix, pos);
	
	gl.bindBuffer(gl.ARRAY_BUFFER, ballVertexBuffer);
	gl.vertexAttribPointer(shader.vertexPositionAttribute, ballVertexBuffer.itemSize, gl.FLOAT, false, 0, 0);

	gl.bindBuffer(gl.ARRAY_BUFFER, ballColorBuffer);
	gl.vertexAttribPointer(shader.vertexColorAttribute, ballColorBuffer.itemSize, gl.FLOAT, false, 0, 0);
	
	gl.bindBuffer(gl.ARRAY_BUFFER, ballNormalBuffer);
	gl.vertexAttribPointer(shader.vertexNormalAttribute, ballNormalBuffer.itemSize, gl.FLOAT, false, 0, 0);
	
	setMatrixUniforms(camera, shader);
	gl.drawArrays(gl.TRIANGLE_STRIP, 0, ballVertexBuffer.numItems);
	
	mvPopMatrix();
}
